package apibasej.db.to;

import apibasej.xml.NodeXML;

@SuppressWarnings("serial")
@NodeXML
public class StatementQuery extends StatementValues{

	@NodeXML(asAttribute=true) private Boolean returnTotalCountWithoutPagination; // se tiver este parâmetro faz o count ...
	
	// se receber irá fazer paginação
	@NodeXML(asAttribute=true) private Integer firstResult;
	@NodeXML(asAttribute=true) private Integer maxResults;
	@NodeXML(needType=true) private Class<?> paginationTransformer;
	
	
	public Boolean getReturnTotalCountWithoutPagination() {
		return returnTotalCountWithoutPagination;
	}
	public Integer getFirstResult() {
		return firstResult;
	}
	public Integer getMaxResults() {
		return maxResults;
	}
	@SuppressWarnings("unchecked")
	public <T extends PaginationTransformer> Class<T> getPaginationTransformer() {
		return (Class<T>)paginationTransformer;
	}
	public void setReturnTotalCountWithoutPagination(Boolean returnTotalCountWithoutPagination) {
		this.returnTotalCountWithoutPagination = returnTotalCountWithoutPagination;
	}
	public void setFirstResult(Integer firstResult) {
		this.firstResult = firstResult;
	}
	public void setMaxResults(Integer maxResults) {
		this.maxResults = maxResults;
	}
	public <T extends PaginationTransformer> void setPaginationTransformer(Class<T> paginationTransformer) {
		this.paginationTransformer = paginationTransformer;
	}
	
	public boolean isReturnTotalCountWithoutPagination() {
		return returnTotalCountWithoutPagination==null?false:returnTotalCountWithoutPagination;
	}
	
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((firstResult == null) ? 0 : firstResult.hashCode());
		result = prime * result + ((maxResults == null) ? 0 : maxResults.hashCode());
		result = prime * result + ((paginationTransformer == null) ? 0 : paginationTransformer.hashCode());
		result = prime * result + ((returnTotalCountWithoutPagination == null) ? 0 : returnTotalCountWithoutPagination.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		
		if(!super.equals(obj)) return false;
		
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		StatementQuery other = (StatementQuery) obj;
		if (firstResult == null) {
			if (other.firstResult != null)
				return false;
		} else if (!firstResult.equals(other.firstResult))
			return false;
		if (maxResults == null) {
			if (other.maxResults != null)
				return false;
		} else if (!maxResults.equals(other.maxResults))
			return false;
		if (paginationTransformer == null) {
			if (other.paginationTransformer != null)
				return false;
		} else if (!paginationTransformer.equals(other.paginationTransformer))
			return false;
		if (returnTotalCountWithoutPagination == null) {
			if (other.returnTotalCountWithoutPagination != null)
				return false;
		} else if (!returnTotalCountWithoutPagination.equals(other.returnTotalCountWithoutPagination))
			return false;
		return true;
	}
	
	
	
}
